<%@page contentType="text/html; charset=utf-8"%>
<%@ include file="./inc/TagLibs.jsp"%>
<c:set var="pageTitle" value="首页" />
<%@ include file="./inc/Title.jsp"%>
<head>
<script src="/js/popup_ext.js"></script>
<script src="/js/jquery.js"></script>
<script language="javascript">
	function setIframeDisplay(flag){
		//nnd,iframe里的东西在平板的触摸屏里模式窗的div挡不住,链接还是有效
		//只好在弹出模式框时隐藏一下iframe
		document.getElementById("MainFrame").style.display=flag;
	}
	function showTsSelect(needTsSelect){
		if(needTsSelect!=null && needTsSelect=="Y"){
			setIframeDisplay("none");
			var url="/system/UserTsSelect.ihtm";
			ShowIframeNoScroll("选择当前帐套",url,300,200,"refreshTs()");
		}
	}
	function refreshTs(){
		if(popRetVal!=null){
			document.getElementById("df_ts_span").innerHTML=popRetVal.substring(0,7);
		}
		setIframeDisplay("");
	}
	function doLogout(){
		<c:if test="${currentUser.user.userType==1 || fn:indexOf(currentUser.privs,';DB_BACK;')!=-1}">
		setIframeDisplay("none");
		ShowConfirmWithMark('确认框','是否自动备份数据库？',340,80,"doLogoutBackup()",'<a href="http://www.ekingcn.com/school/cjwtjjff_1753_253.html" target="_blank">如何设置双重备份到云盘<img src="/images/play_button.gif"></a>');
		</c:if>
		<c:if test="${currentUser.user.userType!=1 && fn:indexOf(currentUser.privs,';DB_BACK;')==-1}">
		window.top.location="/Logout.ihtm";
		</c:if>
	}
	function doLogoutBackup(){
		if(popRetVal!=null){
			var url="/system/DbBackupNew.ihtm";
			ShowIframe("数据备份",url,400,200,"doLogoutCallBack()");
		}else{
			window.location="/Logout.ihtm";
		}
	}
	function doLogoutCallBack(){
		window.location="/Logout.ihtm";
	}
	function doCommNew(){
		setIframeDisplay("none");
		var url="/base/EstablishmentCommunicateNew.ihtm?alert_type=NONE";
		ShowIframe("日程",url,980,440,"setIframeDisplay('')");
	}
	function refreshDesktopWin(){//Desktop.ihtm使用
		if(popRetVal!=null){
			document.getElementById("MainFrame").contentWindow.refreshWin();
		}
		setIframeDisplay("");
	}
	function showAdvicePage(){
		var name=encodeURIComponent("<c:out value="${licenseInfo.enterpriseName}" />");
		var linkman=encodeURIComponent("<c:out value="${currentUser.staffer.stafferName}" />");
		var phone=encodeURIComponent("<c:out value="${enterpriseInfo.phone}" />");
		document.getElementById("MainFrame").src="http://www.ekingcn.com/ask_eking_jg.html?name="+name+"&linkman="+linkman+"&phone="+phone;
	}
	function showClientDialog(){
		var alertType="SHOW";
		<c:if test="${currentUser.user.userType==1 || fn:indexOf(currentUser.privs,';BUSI_BILL;')!=-1}">
			alertType="NONE";
		</c:if>
		setIframeDisplay("none");
		var url="/base/EstablishmentNew.ihtm?type=CLIENT&alert_type="+alertType;
		ShowIframe("客户",url,980,500,"showClientDialogCallBack()");
	}
	function showClientDialogCallBack(){
		if(popRetVal!=null){
			<c:if test="${currentUser.user.userType==1 || fn:indexOf(currentUser.privs,';BUSI_BILL;')!=-1}">
			ShowConfirm('确认框','现在是否开业务单？',340,80,"showClientDialogCallBackExt("+popRetVal+")");
			</c:if>
		}else{
			setIframeDisplay("");
		}
	}
	function showClientDialogCallBackExt(id){
		if(popRetVal!=null){
			doBusinessBillNew(id);
		}
		setIframeDisplay("");
	}
	function doBusinessBillNew(clientId){
		var url="/business/BusinessBillNew.ihtm?type=CLIENT&client_id="+clientId+"&alert_type=FORM";
		showWin(1024,600,url);
	}
	function showEstMoveDialog(estType){
		setIframeDisplay("none");
		var url="/base/EstablishmentMoveForm.ihtm?est_type="+estType;
		var etName="";
		if(estType=="CLIENT"){
			etName="客户";
		}else if(estType=="COOPERATOR"){
			etName="外协商";
		}else if(estType=="PROVIDER"){
			etName="供应商";
		}
		ShowIframeNoScroll(etName+"移交",url,340,220,"setIframeDisplay('')");
	}
	function showBusinessBillDialog(){
		setIframeDisplay("none");
		var url="/base/EstablishmentListForSelect.ihtm?type=CLIENT&ts_id=DF_TS_ID&order_type=BUS_TIME";
		ShowIframe("选择客户",url,900,500,"showBusinessBillDialogCallBack()");
	}
	function showBusinessBillDialogCallBack(){
		if(popRetVal!=null){
			doBusinessBillNew(popRetVal[0]);
		}
		setIframeDisplay("");
	}
	function showBusinessFileDialog(){
		setIframeDisplay("none");
		if(window.applicationCache){//html5
			ShowIframe("传图下单","/business/BusinessFileUpload.ihtm",560,340,"showBusinessFileDialogCallBack()");
		}else{
			ShowIframe("传图下单","/business/BusinessFileForm.ihtm",560,340,"showBusinessFileDialogCallBack()");
		}
	}
	function showBusinessFileDialogCallBack(){
		if(popRetVal!=null){
			var locFn=popRetVal[0];
			var remFn=popRetVal[1];
			var estName=locFn.split(".")[0];
			var xmlHttp=createXMLHttpRequest();
			var url="/base/GetEstablishment.ihtm?est_type=CLIENT&est_name="+encodeURIComponent(estName);
			xmlHttp.open("GET", url, true);
			xmlHttp.onreadystatechange = function(){
				if (xmlHttp.readyState == 4) {
					if (xmlHttp.status == 200) {
						var clientId=xmlHttp.responseText;
						if(clientId!="0"){
							url="/business/BusinessBillNew.ihtm?type=FILE&client_id="+clientId+"&rem_fn="+encodeURIComponent(remFn)+"&alert_type=FORM";
							showWin(1024,600,url);
						}else{
							setIframeDisplay("none");
							url="/base/EstablishmentListForSelect.ihtm?type=CLIENT&ts_id=DF_TS_ID&order_type=BUS_TIME&search_key="+encodeURIComponent(estName);
							ShowIframe("选择客户",url,900,500,"showBusinessFileDialogCallBackExt('"+remFn+"')");
						}
					}
				}
			}
			xmlHttp.send(null);
		}
		setIframeDisplay("");
	}
	function showBusinessFileDialogCallBackExt(remFn){
		if(popRetVal!=null){
			var url="/business/BusinessBillNew.ihtm?type=FILE&client_id="+popRetVal[0]+"&rem_fn="+encodeURIComponent(remFn)+"&alert_type=FORM";
			showWin(1024,600,url);
		}
		setIframeDisplay("");
	}
	function showBusAccountDialog(){
		setIframeDisplay("none");
		var url="/base/EstablishmentListForSelect.ihtm?type=CLIENT&show_all=S&order_type=BUS_TIME";
		ShowIframe("选择客户",url,900,500,"showBusAccountDialogCallBack()");
	}
	function showBusAccountDialogCallBack(){
		if(popRetVal!=null){
			var clientId=popRetVal[0];
			var url="/business/BusinessBillListForAccountForm.ihtm";
			ShowIframeNoScroll("业务对帐",url,340,380,"showBusAccountDialogCallBackExt("+clientId+")");
		}else{
			setIframeDisplay("");
		}
	}
	function showBusAccountDialogCallBackExt(clientId){
		if(popRetVal!=null){
			var startDate=popRetVal[0];
			var endDate=popRetVal[1];
			var type=popRetVal[2];
			var includeSub=popRetVal[3];
			var orderBy=popRetVal[4];
			var linkman=popRetVal[5];
		
			showWin(900,620,'/business/BusinessBillListForAccount.ihtm?client_id='+clientId+'&start_date='+startDate+'&end_date='+endDate+'&linkman='+linkman+'&type='+type+'&include_sub='+includeSub+'&order_by='+orderBy);
		}
		setIframeDisplay("");
	}
	function showDelAccountDialog(){
		setIframeDisplay("none");
		var url="/base/EstablishmentListForSelect.ihtm?type=CLIENT&show_all=S&order_type=BUS_TIME";
		ShowIframe("选择客户",url,900,500,"showDelAccountDialogCallBack()");
	}
	function showDelAccountDialogCallBack(){
		if(popRetVal!=null){
			var clientId=popRetVal[0];
			var url="/business/DeliverBillListForAccountForm.ihtm";
			ShowIframeNoScroll("送货对帐",url,340,340,"showDelAccountDialogCallBackExt("+clientId+")");
		}else{
			setIframeDisplay("");
		}
	}
	function showDelAccountDialogCallBackExt(clientId){
		if(popRetVal!=null){
			var startDate=popRetVal[0];
			var endDate=popRetVal[1];
			var includeSub=popRetVal[2];
			var orderBy=popRetVal[3];
			var linkman=popRetVal[4];
		
			showWin(900,620,'/business/DeliverBillListForAccount.ihtm?client_id='+clientId+'&start_date='+startDate+'&end_date='+endDate+'&linkman='+linkman+'&include_sub='+includeSub+'&order_by='+orderBy);
		}
		setIframeDisplay("");
	}
	function showCooperatorDialog(){
		setIframeDisplay("none");
		var alertType="SHOW";
		<c:if test="${currentUser.user.userType==1 || fn:indexOf(currentUser.privs,';COOP_BILL;')!=-1}">
			alertType="NONE";
		</c:if>
		var url="/base/EstablishmentNew.ihtm?type=COOPERATOR&alert_type="+alertType;
		ShowIframe("外协商",url,980,500,"showCooperatorDialogCallBack()");
	}
	function showCooperatorDialogCallBack(){
		if(popRetVal!=null){
			<c:if test="${currentUser.user.userType==1 || fn:indexOf(currentUser.privs,';COOP_BILL;')!=-1}">
			ShowConfirm('确认框','现在是否开外协单？',340,80,"showCooperatorDialogCallBackExt("+popRetVal+")");
			</c:if>
		}else{
			setIframeDisplay("");
		}
	}
	function showCooperatorDialogCallBackExt(id){
		if(popRetVal!=null){
			doCooperBillNew(id);
		}
		setIframeDisplay("");
	}
	function doCooperBillNew(cooperatorId){
		var url="/cooper/CooperBillNew.ihtm?cooperator_id="+cooperatorId+"&alert_type=FORM";
		showWin(1024,600,url);
	}
	function showCooperBillDialog(){
		setIframeDisplay("none");
		var url="/base/EstablishmentListForSelect.ihtm?type=COOPERATOR&ts_id=DF_TS_ID&order_type=BUS_TIME";
		ShowIframe("选择外协商",url,900,500,"showCooperBillDialogCallBack()");
	}
	function showCooperBillDialogCallBack(){
		if(popRetVal!=null){
			doCooperBillNew(popRetVal[0]);
		}
		setIframeDisplay("");
	}
	function showCooAccountDialog(){
		setIframeDisplay("none");
		var url="/base/EstablishmentListForSelect.ihtm?type=COOPERATOR&show_all=S&order_type=BUS_TIME";
		ShowIframe("选择外协商",url,900,500,"showCooAccountDialogCallBack()");
	}
	function showCooAccountDialogCallBack(){
		if(popRetVal!=null){
			var estId=popRetVal[0];
			var url="/cooper/CooperBillListForAccountForm.ihtm";
			ShowIframeNoScroll("外协对帐",url,340,310,"showCooAccountDialogCallBackExt("+estId+")");
		}else{
			setIframeDisplay("");
		}
	}
	function showCooAccountDialogCallBackExt(estId){
		if(popRetVal!=null){
			var startDate=popRetVal[0];
			var endDate=popRetVal[1];
			var type=popRetVal[2];
			var orderBy=popRetVal[3];
			showWin(900,620,'/cooper/CooperBillListForAccount.ihtm?cooperator_id='+estId+'&start_date='+startDate+'&end_date='+endDate+'&type='+type+'&order_by='+orderBy);
		}
		setIframeDisplay("");
	}
	function showGatAccountDialog(){
		setIframeDisplay("none");
		var url="/base/EstablishmentListForSelect.ihtm?type=COOPERATOR&show_all=S&order_type=BUS_TIME";
		ShowIframe("选择外协商",url,900,500,"showGatAccountDialogCallBack()");
	}
	function showGatAccountDialogCallBack(){
		if(popRetVal!=null){
			var estId=popRetVal[0];
			var url="/cooper/GatherBillListForAccountForm.ihtm";
			ShowIframeNoScroll("收货对帐",url,340,310,"showGatAccountDialogCallBackExt("+estId+")");
		}else{
			setIframeDisplay("");
		}
	}
	function showGatAccountDialogCallBackExt(estId){
		if(popRetVal!=null){
			var startDate=popRetVal[0];
			var endDate=popRetVal[1];
			var orderBy=popRetVal[2];
			showWin(900,620,'/cooper/GatherBillListForAccount.ihtm?cooperator_id='+estId+'&start_date='+startDate+'&end_date='+endDate+'&order_by='+orderBy);
		}
		setIframeDisplay("");
	}
	function showProviderDialog(){
		setIframeDisplay("none");
		var alertType="SHOW";
		<c:if test="${currentUser.user.userType==1 || fn:indexOf(currentUser.privs,';PURC_BUY;')!=-1}">
			alertType="NONE";
		</c:if>
		var url="/base/EstablishmentNew.ihtm?type=PROVIDER&alert_type="+alertType;
		ShowIframe("供应商",url,980,500,"showProviderDialogCallBack()");
	}
	function showProviderDialogCallBack(){
		if(popRetVal!=null){
			<c:if test="${currentUser.user.userType==1 || fn:indexOf(currentUser.privs,';PURC_BUY;')!=-1}">
			ShowConfirm('确认框','现在是否开采购单？',340,80,"showProviderDialogCallBackExt('BUY',"+popRetVal+")");
			</c:if>
		}else{
			setIframeDisplay("");
		}
	}
	function showProviderDialogCallBackExt(type,id){
		if(popRetVal!=null){
			doPurchaseBillNew(type,id);
		}
		setIframeDisplay("");
	}
	function doPurchaseBillNew(type,providerId){
		var url="/purchase/PurchaseBillNew.ihtm?type="+type+"&provider_id="+providerId+"&alert_type=FORM";
		showWin(1024,600,url);
	}
	function showPurAccountDialog(){
		setIframeDisplay("none");
		var url="/base/EstablishmentListForSelect.ihtm?type=PROVIDER&show_all=S&order_type=BUS_TIME";
		ShowIframe("选择供应商",url,900,500,"showPurAccountDialogCallBack()");
	}
	function showPurAccountDialogCallBack(){
		if(popRetVal!=null){
			var estId=popRetVal[0];
			var url="/purchase/PurchaseBillListForAccountForm.ihtm";
			ShowIframeNoScroll("采购对帐",url,340,310,"showPurAccountDialogCallBackExt("+estId+")");
		}else{
			setIframeDisplay("");
		}
	}
	function showPurAccountDialogCallBackExt(estId){
		if(popRetVal!=null){
			var startDate=popRetVal[0];
			var endDate=popRetVal[1];
			var type=popRetVal[2];
			var orderBy=popRetVal[3];
			showWin(900,620,'/purchase/PurchaseBillListForAccount.ihtm?provider_id='+estId+'&start_date='+startDate+'&end_date='+endDate+'&type='+type+'&order_by='+orderBy);
		}
		setIframeDisplay("");
	}
	function showPayBillDialog(){
		setIframeDisplay("none");
		var url="/finance/PayTypeSelect.ihtm";
		ShowIframeNoScroll("选择付款类型",url,240,240,"showPayBillDialogCallBack()");
	}
	function showPayBillDialogCallBack(){
		if(popRetVal!=null){
			var url="/finance/PayBillNew.ihtm?alert_type=SHOW&pay_type="+popRetVal;
			showWin(1024,600,url);
		}
		setIframeDisplay("");
	}
	function showAdjustBillDialog(){
		setIframeDisplay("none");
		var url="/finance/AdjustTypeSelect.ihtm";
		ShowIframeNoScroll("选择调帐类型",url,240,380,"showAdjustBillDialogCallBack()");
	}
	function showAdjustBillDialogCallBack(){
		if(popRetVal!=null){
			var url="/finance/AdjustBillNew.ihtm?adjust_type="+popRetVal+"&alert_type=SHOW";
			showWin(1024,600,url);
		}
		setIframeDisplay("");
	}
	function showBusinessBillReorderDialog(){
		setIframeDisplay("none");
		var url="/base/EstablishmentListForSelect.ihtm?type=CLIENT&ts_id=DF_TS_ID&order_type=BUS_TIME&show_all=S";
		ShowIframe("选择客户",url,900,500,"showBusinessBillReorderDialogCallBack()");
	}
	function showBusinessBillReorderDialogCallBack(){
		if(popRetVal!=null){
			var url="/business/BusinessBillListForReorder.ihtm?client_id="+popRetVal[0];
			ShowIframe("选择业务单",url,900,500,"showBusinessBillReorderDialogCallBackExt()");
		}else{
			setIframeDisplay("");
		}
	}
	function showBusinessBillReorderDialogCallBackExt(){
		if(popRetVal!=null){
			var url="/business/BusinessBillNew.ihtm?type=TEMPLATE&template_id="+popRetVal+"&alert_type=FORM";
			showWin(1024,600,url);
		}
		setIframeDisplay("");
	}
	function showStatus(){
		window.status="时间：<fmt:formatDate value="${currentTime}" pattern="yyyy-MM-dd EEE"/>  当前操作员：${currentUser.staffer.stafferName}  使用单位：${licenseInfo.enterpriseName}";
	}
	function showTsPage(){
		setTimeout("showTsSelect('${currentUser.needTsSelect}');",1000);
	}
	window.onbeforeunload = function(){
		var n = window.event.screenX - window.screenLeft;   
		var b = n > document.documentElement.scrollWidth-20;   
		if(b && window.event.clientY < 0 || window.event.altKey){
			var xmlHttp=createXMLHttpRequest();
			xmlHttp.open("GET", "/Logout.ihtm",true);
			xmlHttp.send(null);
		}
	}
	function doImpo(formUrl,targetUrl){
		ShowIframe("导入Excel",formUrl,560,300,"doImpoCallBack('"+targetUrl+"')");
	}
	function doImpoCallBack(targetUrl){
		if(popRetVal){
			document.getElementById("LoadProcess").style.top=(document.body.clientHeight/2-50)+"px";
			document.getElementById("LoadProcess").style.left=(document.body.clientWidth/2-100)+"px";
			document.getElementById("LoadProcess").style.display="";
			var fileName = popRetVal;
			var url;
			if(targetUrl.indexOf("?")==-1){
				url=targetUrl+"?file_name=" + encodeURIComponent(fileName);
			}else{
				url=targetUrl+"&file_name=" + encodeURIComponent(fileName);
			}
			var xmlHttp=createXMLHttpRequest();
			xmlHttp.open("GET", url, true);
			xmlHttp.onreadystatechange = function(){
				if (xmlHttp.readyState == 4) {
		      		if (xmlHttp.status == 200) {
			      		document.getElementById("LoadProcess").style.display="none";
			      		showWin(560,300,"/ImpoSuccess.ihtm");
		      		}
		      	}
		    };
		    xmlHttp.send(null);
		}
	}
</script>
<link rel="stylesheet" type="text/css" href="/css/base.css" />
<link rel="stylesheet" type="text/css" href="/css/defualt.css" />
<link rel="stylesheet" type="text/css" href="/css/GlobalMenu.css" />
<script type="text/javascript" src="/js/Common.js"></script>
<script type="text/javascript" src="/js/GlobalMenu.js"></script>

<link href="/css/dtree.css" rel="stylesheet" type="text/css">
<script src="/js/dtree.js"></script>

</head>
<body>
	<div class="Wrap">
		<div class="Container">
		
    		<div class="Heading">
    			<div class="heading_logo">
    				<div class="heading_right">
    					<div class="company">
				            <a class="select" tabindex="21" onClick="showTsSelect('Y');" title="点击切换当前的开单帐套">
				                <div>
					                <p>
						                <span id="df_ts_span">
						                <c:if test="${currentUser.user.dfTsId==0}">请选开单帐套</c:if>
										<c:if test="${currentUser.user.dfTsId!=0}"><commonTag:cutString source="${currentUser.dfTsName}" subLength="14" appendString="" /></c:if>
						                </span>
					                </p>
				                </div>
				            </a>
				        </div>
        				<div class="edit">
	            			<ul class="edit-link">
	            				<c:if test="${endDiff!=''}">
	            				<li><span style="font-weight:bold;">网络下单系统</span>距离到期还有<span style="color:red">${endDiff}</span>天</li>
	            				</c:if>
	                			<li class="ico-home"><a tabindex="22" href="/Desktop.ihtm" target="MainFrame">桌面</a></li>
	                			<li class="ico-code"><a href="javascript:showWin(340,300,'/system/AccountEdit.ihtm?alert_type=SHOW');">修改密码</a></li>
	                			<li class="ico-sms"><a href="javascript:javascript:showWin(500,450,'/app/GetAppBarcode.ihtm');">手机APP</a></li>
	                			<li class="ico-help"><a href="javascript:showAdvicePage();">帮助</a></li>
	                			<li class="ico-out"><a tabindex="24" id="lnkExit" href="javascript:doLogout();" >退出</a></li>
	            			</ul>
        				</div>
        				<ul id="MainMenu" class="GlobalMenu ClearFix"></ul>
    				</div>
    			</div>
			</div>
			
			<div class="Content">
    			<iframe id="MainFrame" name="MainFrame" class="MainFrame" frameborder="0" src="/Desktop.ihtm"></iframe>
    		</div>
    		
		</div>
	</div>
	<jsp:include page="./LeftMenu.jsp" flush="true" />
	<%@ include file="./inc/LoadingDiv.jsp"%>
</body>
</html>

<!-- 文件太大,不能编译,只好拆分出来(为什么BusinessBillForm.jsp就不会?这里的最大限度应该是指jsp编译后的servlet的单个function的大小,而不是jsp) -->
<!-- 不能用@include方式(未编译前的饱含),jsp:include是输出后的包含 -->
<jsp:include page="./MainMenuData1.jsp" flush="true" />
<jsp:include page="./MainMenuData2.jsp" flush="true" />

<script language="javascript">
function OnResize(){
    var cw = document.documentElement.clientWidth;
    var ch = document.documentElement.clientHeight;
    MainFrame.style.width  = (cw)+'px';
    MainFrame.style.height = (ch-68)+'px';
};

var MainFrame = $('MainFrame');
var MainMenu =  $('MainMenu');

(function(){
    window.onresize = OnResize;
    OnResize();
    
    var gmm = new GlobalMenuMgr( MainMenu, GM_Data, MainFrame );
    
	showStatus();
	showTsPage();
})();
</script>
